package com.studentgrowth.service.auth.impl;

import com.studentgrowth.service.sms.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class VerificationCodeServiceImpl implements com.studentgrowth.service.sms.VerificationCodeService {

    private static final Logger log = LoggerFactory.getLogger(VerificationCodeServiceImpl.class);

    private final SmsService smsService;

    public VerificationCodeServiceImpl(SmsService smsService) {
        this.smsService = smsService;
    }

    @Override
    public String generateAndSendCode(String phoneNumber) {
        // 生成6位随机验证码
        String code = String.format("%06d", (int) (Math.random() * 1000000));

        // 发送验证码
        smsService.sendVerificationCode(phoneNumber, code);

        // 暂时只打印日志，不实际发送短信
        log.info("模拟发送验证码到手机: {}, 验证码: {}", phoneNumber, code);

        return code;
    }

    @Override
    public boolean verifyCode(String phoneNumber, String code) {
        // 暂时直接返回true，等待短信服务申请完成后再实现实际验证逻辑
        log.info("模拟验证码校验: phoneNumber={}, code={}", phoneNumber, code);
        return true;
    }
}
